package _interview150;

import _object.TreeNode;

/**
 * 530. 二叉搜索树的最小绝对差
 */
public class No530 {
    private int preVal = Integer.MAX_VALUE;
    private int ans = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {
        dfs(root);
        return ans;
    }

    public void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.left);
        ans = Math.min(ans, Math.abs(node.val - preVal));
        preVal = node.val;
        dfs(node.right);
    }
}
